/*     */ package com.umeng.analytics;
/*     */ 
/*     */ import android.content.Context;
/*     */ import android.content.SharedPreferences;
/*     */ import android.content.SharedPreferences.Editor;
/*     */ import android.content.pm.PackageManager;
/*     */ import android.os.Handler;
/*     */ import android.os.HandlerThread;
/*     */ import com.umeng.common.Log;
/*     */ import com.umeng.common.b;
/*     */ import java.io.BufferedReader;
/*     */ import java.io.ByteArrayInputStream;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ import java.io.InputStreamReader;
/*     */ import java.net.URLEncoder;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import org.apache.http.HttpEntity;
/*     */ import org.apache.http.HttpHost;
/*     */ import org.apache.http.HttpResponse;
/*     */ import org.apache.http.StatusLine;
/*     */ import org.apache.http.client.ClientProtocolException;
/*     */ import org.apache.http.client.HttpClient;
/*     */ import org.apache.http.client.entity.UrlEncodedFormEntity;
/*     */ import org.apache.http.client.methods.HttpPost;
/*     */ import org.apache.http.entity.InputStreamEntity;
/*     */ import org.apache.http.impl.client.DefaultHttpClient;
/*     */ import org.apache.http.message.BasicNameValuePair;
/*     */ import org.apache.http.params.BasicHttpParams;
/*     */ import org.apache.http.params.HttpConnectionParams;
/*     */ import org.apache.http.params.HttpParams;
/*     */ import org.json.JSONObject;
/*     */ 
/*     */ public abstract class d
/*     */   implements i, com.umeng.analytics.onlineconfig.c
/*     */ {
/*  46 */   private final a a = new a();
/*     */ 
/*  48 */   private final Object b = new Object();
/*     */   private final Handler c;
/*  51 */   protected final c d = new c();
/*  52 */   protected final com.umeng.analytics.a.f e = new com.umeng.analytics.a.f();
/*     */ 
/*  54 */   protected final int f = 1;
/*  55 */   protected final int g = 2;
/*  56 */   protected final int h = 3;
/*     */ 
/*  58 */   protected final int i = 4;
/*  59 */   protected final int j = 5;
/*     */ 
/*  61 */   private final String m = "body";
/*  62 */   private final String n = "header";
/*     */ 
/*  64 */   private int o = -1;
/*  65 */   private long p = -1L;
/*  66 */   private long q = -1L;
/*  67 */   private long r = -1L;
/*     */ 
/*  69 */   String k = null;
/*  70 */   String l = null;
/*     */ 
/*  72 */   private boolean s = false;
/*     */ 
/*     */   public d()
/*     */   {
/*  76 */     HandlerThread localHandlerThread = new HandlerThread("MobclickAgent");
/*  77 */     localHandlerThread.start();
/*  78 */     this.c = new Handler(localHandlerThread.getLooper());
/*     */   }
/*     */ 
/*     */   public void e(Context paramContext) {
/*  82 */     a(paramContext, 1);
/*     */   }
/*     */ 
/*     */   public synchronized void a(Context paramContext, int paramInt) {
/*  86 */     if ((!this.s) && (paramInt == 4)) {
/*  87 */       a(paramContext);
/*  88 */       f(paramContext);
/*     */ 
/*  90 */       this.s = true;
/*     */     }
/*     */ 
/*  93 */     if (paramInt == 5) {
/*  94 */       this.d.a(paramContext);
/*  95 */       return;
/*     */     }
/*     */ 
/*  98 */     if (b(paramContext, paramInt))
/*     */     {
/* 100 */       this.c.post(new b(paramContext));
/*     */     }
/*     */ 
/* 103 */     if (this.d.b())
/*     */     {
/* 105 */       this.c.post(new a(paramContext));
/*     */     }
/*     */   }
/*     */ 
/*     */   private void a(Context paramContext) {
/* 110 */     if (this.o != -1) {
/* 111 */       return;
/*     */     }
/*     */ 
/* 114 */     int[] arrayOfInt = j.i(paramContext);
/*     */ 
/* 116 */     this.o = arrayOfInt[0];
/* 117 */     this.p = arrayOfInt[1];
/*     */ 
/* 119 */     if ((this.o == 4) || (this.o == 6)) {
/* 120 */       SharedPreferences localSharedPreferences = j.e(paramContext);
/*     */ 
/* 122 */       this.q = localSharedPreferences.getLong("last_report_time", -1L);
/*     */     }
/*     */   }
/*     */ 
/*     */   public void f(Context paramContext) {
/* 127 */     this.a.a(paramContext);
/* 128 */     this.a.a(this);
/*     */   }
/*     */ 
/*     */   private void b(Context paramContext)
/*     */   {
/*     */     SharedPreferences localSharedPreferences;
/* 133 */     if ((this.o == 6) || (this.o == 4))
/*     */     {
/* 135 */       localSharedPreferences = j.e(paramContext);
/*     */ 
/* 137 */       localSharedPreferences.edit().putLong("last_report_time", this.q).commit();
/*     */     }
/*     */ 
/* 140 */     if (this.r != -1L) {
/* 141 */       this.e.f = this.r;
/*     */ 
/* 143 */       localSharedPreferences = j.c(paramContext);
/* 144 */       localSharedPreferences.edit().putLong("req_time", this.r).commit();
/*     */     }
/*     */   }
/*     */ 
/*     */   boolean b(Context paramContext, int paramInt)
/*     */   {
/* 150 */     if (!b.n(paramContext)) {
/* 151 */       return false;
/*     */     }
/*     */ 
/* 154 */     switch (paramInt) {
/*     */     case 4:
/* 156 */       if (this.o == 1) {
/* 157 */         return true;
/*     */       }
/*     */     case 1:
/* 160 */       if (this.o == 0)
/*     */       {
/* 162 */         return true;
/* 163 */       }if ((this.o == 6) && (System.currentTimeMillis() - this.q > this.p))
/*     */       {
/* 165 */         this.q = System.currentTimeMillis();
/*     */ 
/* 167 */         return true;
/* 168 */       }if ((this.o == 4) && (System.currentTimeMillis() - this.q > g.g))
/*     */       {
/* 170 */         this.q = System.currentTimeMillis();
/*     */ 
/* 172 */         return true;
/* 173 */       }if ((this.o == 5) && (b.l(paramContext))) {
/* 174 */         return true;
/*     */       }
/*     */ 
/*     */       break;
/*     */     case 2:
/* 179 */       return true;
/*     */     case 3:
/* 182 */       break;
/*     */     case 5:
/*     */     }
/*     */ 
/* 187 */     return false;
/*     */   }
/*     */ 
/*     */   private String c(Context paramContext)
/*     */   {
/* 192 */     if (!this.e.b()) {
/* 193 */       this.e.b(paramContext, new String[] { this.l, this.k });
/*     */     }
/*     */ 
/* 196 */     StringBuffer localStringBuffer1 = new StringBuffer();
/* 197 */     localStringBuffer1.append(this.e.w);
/* 198 */     localStringBuffer1.append("/");
/* 199 */     localStringBuffer1.append(this.e.x);
/* 200 */     localStringBuffer1.append(" ");
/*     */     try
/*     */     {
/* 203 */       StringBuffer localStringBuffer2 = new StringBuffer();
/* 204 */       localStringBuffer2.append(paramContext.getPackageManager().getApplicationLabel(paramContext.getApplicationInfo()).toString());
/* 205 */       localStringBuffer2.append("/");
/* 206 */       localStringBuffer2.append(this.e.t);
/* 207 */       localStringBuffer2.append(" ");
/* 208 */       localStringBuffer2.append(this.e.g);
/* 209 */       localStringBuffer2.append("/");
/* 210 */       localStringBuffer2.append(this.e.i);
/*     */ 
/* 212 */       localStringBuffer2.append(" ");
/* 213 */       localStringBuffer2.append(this.e.d);
/*     */ 
/* 215 */       localStringBuffer1.append(URLEncoder.encode(localStringBuffer2.toString(), "UTF-8"));
/*     */     } catch (Exception localException) {
/* 217 */       localException.printStackTrace();
/*     */     }
/*     */ 
/* 220 */     return localStringBuffer1.toString();
/*     */   }
/*     */ 
/*     */   private void d(Context paramContext)
/*     */   {
/* 229 */     JSONObject localJSONObject = g(paramContext);
/*     */ 
/* 231 */     if ((localJSONObject == null) || (localJSONObject.isNull("body"))) {
/* 232 */       return;
/*     */     }
/*     */ 
/* 235 */     String str = null;
/* 236 */     for (int i1 = 0; i1 < g.r.length; i1++)
/*     */     {
/* 238 */       str = a(paramContext, localJSONObject, g.r[i1]);
/* 239 */       if (str != null)
/*     */       {
/*     */         break;
/*     */       }
/*     */     }
/*     */ 
/* 245 */     if (str != null) {
/* 246 */       j.j(paramContext);
/* 247 */       Log.a("MobclickAgent", "send applog succeed :" + str);
/*     */     }
/*     */     else {
/* 250 */       this.q = -1L;
/*     */ 
/* 252 */       j.b(paramContext, localJSONObject, b.d(paramContext));
/* 253 */       Log.a("MobclickAgent", "send applog failed");
/*     */     }
/*     */ 
/* 256 */     b(paramContext);
/*     */   }
/*     */ 
/*     */   JSONObject g(Context paramContext)
/*     */   {
/* 261 */     JSONObject localJSONObject = new JSONObject();
/*     */     try
/*     */     {
/* 265 */       if (!this.e.b()) {
/* 266 */         this.e.b(paramContext, new String[] { this.l, this.k });
/*     */       }
/*     */ 
/* 269 */       if (!this.e.a()) {
/* 270 */         Log.b("MobclickAgent", "protocol Header need Appkey or Device ID ,Please check AndroidManifest.xml ");
/* 271 */         return null;
/*     */       }
/*     */ 
/* 274 */       this.d.b(paramContext);
/*     */ 
/* 276 */       if (this.d.a() <= 0) {
/* 277 */         Log.c("MobclickAgent", "no message to send");
/* 278 */         return null;
/*     */       }
/*     */ 
/* 281 */       if (!this.d.c()) {
/* 282 */         throw new Exception("protocol Body has invalid field: " + this.d.d().toString());
/*     */       }
/*     */ 
/* 285 */       localJSONObject.put("header", new e(this));
/*     */ 
/* 290 */       localJSONObject.put("body", this.d.d());
/*     */ 
/* 292 */       this.d.e();
/*     */ 
/* 294 */       return localJSONObject;
/*     */     }
/*     */     catch (Exception localException) {
/* 297 */       Log.b("MobclickAgent", "", localException);
/* 298 */       j.j(paramContext);
/*     */     } catch (Error localError) {
/* 300 */       Log.b("MobclickAgent", "Error:" + localError.getMessage());
/* 301 */       j.j(paramContext);
/*     */     }
/*     */ 
/* 304 */     return null;
/*     */   }
/*     */ 
/*     */   private String a(InputStream paramInputStream) {
/* 308 */     BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(paramInputStream), 64);
/* 309 */     StringBuilder localStringBuilder = new StringBuilder();
/*     */ 
/* 311 */     Object localObject1 = null;
/*     */     try {
/* 313 */       while ((localObject1 = localBufferedReader.readLine()) != null)
/* 314 */         localStringBuilder.append(localObject1 + "\n");
/*     */     }
/*     */     catch (IOException localIOException1) {
/* 317 */       Log.b("MobclickAgent", 
/* 318 */         "Caught IOException in convertStreamToString()", localIOException1);
/* 319 */       return null;
/*     */     } finally {
/*     */       try {
/* 322 */         paramInputStream.close();
/*     */       } catch (IOException localIOException3) {
/* 324 */         Log.b("MobclickAgent", 
/* 325 */           "Caught IOException in convertStreamToString()", localIOException3);
/*     */ 
/* 327 */         return null;
/*     */       }
/*     */     }
/* 330 */     return localStringBuilder.toString();
/*     */   }
/*     */ 
/*     */   private String a(Context paramContext, JSONObject paramJSONObject, String paramString)
/*     */   {
/* 335 */     HttpPost localHttpPost = new HttpPost(paramString);
/* 336 */     BasicHttpParams localBasicHttpParams = new BasicHttpParams();
/* 337 */     HttpConnectionParams.setConnectionTimeout(localBasicHttpParams, 10000);
/* 338 */     HttpConnectionParams.setSoTimeout(localBasicHttpParams, 30000);
/* 339 */     DefaultHttpClient localDefaultHttpClient = new DefaultHttpClient(localBasicHttpParams);
/*     */ 
/* 342 */     localHttpPost.addHeader("X-Umeng-Sdk", c(paramContext));
/*     */     try
/*     */     {
/* 345 */       String str1 = h.a(paramContext);
/* 346 */       if (str1 != null) {
/* 347 */         localObject1 = new HttpHost(str1, 80);
/* 348 */         localDefaultHttpClient.getParams().setParameter(
/* 349 */           "http.route.default-proxy", localObject1);
/*     */       }
/*     */ 
/* 352 */       Object localObject1 = paramJSONObject.toString();
/*     */ 
/* 354 */       Log.a("MobclickAgent", (String)localObject1);
/*     */ 
/* 356 */       if (g.t) {
/* 357 */         localObject1 = "content=" + (String)localObject1;
/* 358 */         localObject2 = com.umeng.common.util.f.a((String)localObject1, "utf-8");
/* 359 */         localHttpPost.addHeader("Content-Encoding", "deflate");
/* 360 */         localObject3 = new InputStreamEntity(
/* 361 */           new ByteArrayInputStream((byte[])localObject2), 
/* 362 */           com.umeng.common.util.f.a);
/* 363 */         localHttpPost.setEntity((HttpEntity)localObject3);
/*     */       } else {
/* 365 */         localObject2 = new ArrayList(
/* 366 */           1);
/* 367 */         ((List)localObject2).add(new BasicNameValuePair("content", (String)localObject1));
/* 368 */         localHttpPost.setEntity(new UrlEncodedFormEntity((List)localObject2, 
/* 369 */           "UTF-8"));
/*     */       }
/*     */ 
/* 372 */       Object localObject2 = new Date();
/* 373 */       Object localObject3 = localDefaultHttpClient.execute(localHttpPost);
/* 374 */       Date localDate = new Date();
/* 375 */       this.r = (localDate.getTime() - ((Date)localObject2).getTime());
/*     */ 
/* 377 */       if (((HttpResponse)localObject3).getStatusLine().getStatusCode() == 200) {
/* 378 */         Log.a("MobclickAgent", "Sent message to " + paramString);
/*     */ 
/* 380 */         HttpEntity localHttpEntity = ((HttpResponse)localObject3).getEntity();
/*     */ 
/* 382 */         if (localHttpEntity != null) {
/* 383 */           InputStream localInputStream = localHttpEntity.getContent();
/* 384 */           return a(localInputStream);
/*     */         }
/*     */ 
/* 388 */         return null;
/*     */       }
/* 390 */       return null;
/*     */     }
/*     */     catch (ClientProtocolException localClientProtocolException)
/*     */     {
/* 395 */       Log.b("MobclickAgent", 
/* 396 */         "ClientProtocolException,Failed to send message.", localClientProtocolException);
/* 397 */       return null;
/*     */     } catch (IOException localIOException) {
/* 399 */       Log.b("MobclickAgent", "IOException,Failed to send message.", localIOException);
/* 400 */     }return null;
/*     */   }
/*     */ 
/*     */   public void a(int paramInt, long paramLong)
/*     */   {
/* 459 */     this.o = paramInt;
/* 460 */     this.p = paramLong;
/*     */   }
/*     */ 
/*     */   private final class a
/*     */     implements Runnable
/*     */   {
/*     */     private Context b;
/*     */ 
/*     */     a(Context arg2)
/*     */     {
/*     */       Object localObject;
/* 436 */       this.b = localObject.getApplicationContext();
/*     */     }
/*     */ 
/*     */     public void run() {
/*     */       try {
/* 441 */         synchronized (d.a(d.this)) {
/* 442 */           d.this.d.a(this.b);
/*     */         }
/*     */       } catch (Exception localException1) {
/* 445 */         Log.b("MobclickAgent", "Exception occurred in ReportMessageHandler", localException1);
/*     */       } catch (Error localError) {
/* 447 */         Log.b("MobclickAgent", "Error : " + localError.getMessage());
/*     */         try {
/* 449 */           j.j(this.b);
/*     */         } catch (Exception localException2) {
/* 451 */           localException2.printStackTrace();
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   private final class b
/*     */     implements Runnable
/*     */   {
/*     */     private Context b;
/*     */ 
/*     */     b(Context arg2)
/*     */     {
/*     */       Object localObject;
/* 410 */       this.b = localObject.getApplicationContext();
/*     */     }
/*     */ 
/*     */     public void run() {
/*     */       try {
/* 415 */         synchronized (d.a(d.this)) {
/* 416 */           d.a(d.this, this.b);
/*     */         }
/*     */       } catch (Exception localException1) {
/* 419 */         Log.b("MobclickAgent", "Exception occurred in ReportMessageHandler", localException1);
/*     */       } catch (Error localError) {
/* 421 */         Log.b("MobclickAgent", "Error : " + localError.getMessage());
/*     */         try {
/* 423 */           j.j(this.b);
/*     */         } catch (Exception localException2) {
/* 425 */           localException2.printStackTrace();
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\umeng_sdk.jar
 * Qualified Name:     com.umeng.analytics.d
 * JD-Core Version:    0.6.2
 */